<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Layout
{

    var $obj;
    var $layout;

    function __construct($layout = "")
    {
        $this->obj =& get_instance();
        $this->layout = $layout;
    }

    function setLayout($layout)
    {
        $this->layout = $layout;
    }

    function view($view, $data = null, $return = false)
    {
        if($this->obj->session->userdata('logged_in'))
        {
            $session_data = $this->obj->session->userdata('logged_in');
            $data['is_logged_in'] = true;
            $data['fullname'] = $session_data['fullname'];
        }
        else
        {
            $data['is_logged_in'] = false;
        }
        $data['product_categories'] = $this->obj->mproductcategory->get_product_category();
        $data['product_type'] = $this->obj->mproducttype->get_product_type();
        $loadedData = array();
        $loadedData['content_for_layout'] = $this->obj->load->view($view, $data, true);

        if ($return) {
            $output = $this->obj->load->view($this->layout, $loadedData, true);
            return $output;
        } else {
            $this->obj->load->view($this->layout, $loadedData, false);
        }
    }
}